<?php
/**
 * Controller_Action
 * 
 * @author naspeh
 * @version $Id: Action.php 661 2008-06-16 10:38:02Z naspeh $
 */
class Core_Controller_Action extends Zend_Controller_Action
{
    /**
     * Начальные установки для действий.
     *
     * @return Zend_Controller_Action
     */
    public function init()
    {
        Zend_Controller_Action_HelperBroker::addHelper(new Core_Controller_Action_Helper_FlashMessenger());
        return $this;
    }
    /**
     * Redirect to another URL
     *
     * Proxies to {@link Zend_Controller_Action_Helper_Redirector::gotoUrl()}.
     *
     * @param string $url
     * @param array $options Options to be used when redirecting
     * @return void
     */
    protected function _redirect($url, array $options = array())
    {
        $this->_helper->FlashMessenger->addMessages(Core_Message::get());
        return parent::_redirect($url, $options);    
    }
    /**
     * Проверяет параметры
     *
     * @param array $allowed
     * @return Core_Controller_Action 
     */
    protected function _securityParams_(array $allowed)
    {
        $params = $this->getRequest()->getParams();
        $params = array_diff_key($params, array_flip(array('module', 'controller', 'action')));
        $isError = false;
        $allowedResult = array();
        foreach ($allowed as $key => $regx) {
            if (is_int($key)) {
                $key = $regx;
                $regx = false;
            }
            $allowedResult[$key] = $regx;
        }
        foreach ($params as $key => $value) {
            if (!isset($allowedResult[$key])) {
                $isError = true;
                break;
            }
            $regx = $allowedResult[$key];
            if (false !== $regx && !preg_match('/^' . $regx . '$/', $value)) {
                $isError = true;
                break;
            }
        }
        if ($isError) {
            throw new Core_Exception('badUrlParams#', 404);
        }
        return $this;
    }
}